package rules;

import game.Board;
import game.GridLockState;
import game.Piece;
import gps.api.GPSState;

import java.awt.Point;

public class MoveLeft extends Move {
	
	public MoveLeft(Piece piece, int times){
		this.piece = piece;
		this.times = times;
	}
	
	@Override
	protected GPSState makeMovement(Piece piece, GPSState state){
		Point pointToMove = new Point(piece.getPosition().x - times, piece.getPosition().y);
		//GPSState answer = new GridLockState((Board)((GridLockState)state).getBoard().myClone());
//		if(((GridLockState)answer).getBoard().movePiece(piece, pointToMove)){
//			return answer;
//		}
//		return null;
		Board ansBoard; 
		if((ansBoard=((GridLockState)state).getBoard().movePiece(piece, pointToMove)) == null){
			return null;
		}
		GPSState ans = new GridLockState(ansBoard);
		return ans;
	}

	@Override
	public String getName() {
		return "piece " + piece.getId() + " MoveLeft " + this.times + " times, ";
	}
	
	public String toString(){
		return getName();
	}

}
